package me.tonywang.helloquartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.TriggerKey.triggerKey;

// @see CronTriggerFactoryBean
// @see JobDetailFactoryBean
public class JobMain {
    public static void main(String[] args) throws SchedulerException  {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(MethodInvokingJobDetailFactoryBean.MethodInvokingJob.class)
                .withIdentity("myJob")
                .build();

        String cronExpression = "0/1 * * * * ?";
        
        Trigger trigger = newTrigger()
                .withIdentity(triggerKey("myTrigger", "myTriggerGroup"))
                .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
                .build();

        scheduler.scheduleJob(job, trigger);
        scheduler.start();

    }
}
